from django.db import models

from sportsground.utils.baseModels import BaseModels


class Coupon(BaseModels):
    class Meta():
        db_table = 'Venue_coupon'
        verbose_name = '馆场优惠券'
        verbose_name_plural = verbose_name

    name = models.CharField(max_length=20,null=True,verbose_name="名称")
    desc = models.CharField(max_length=200,null=True,verbose_name="描述")
    venue = models.ForeignKey(to="Venue.Venue", null=True, on_delete=models.CASCADE, verbose_name="对应场馆")
    reach = models.IntegerField(verbose_name="达到")
    derate = models.IntegerField(verbose_name="减免")
    startTime = models.DateTimeField(verbose_name="开始时间")
    endTime = models.DateTimeField(verbose_name="结束时间")

    def Info(self):
        return {
            "id": self.id,
            "name": self.name,
            "desc": self.desc,
            "venueId": self.venue.id,
            "reach": self.reach,
            "derate": self.derate,
            "startTime": self.startTime,
            "endTime": self.endTime
        }

    @classmethod
    def create(cls,venue,name,desc,reach,derate,startTime,endTime):
        coupon = cls(venue=venue,name=name,desc=desc,reach=reach,derate=derate,startTime=startTime,endTime=endTime)
        coupon.save()
        return coupon
